package com.example.stuwork.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * 测试提交实体类
 * 对应 quiz_submission 表
 */
public class QuizSubmission implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 提交ID
     */
    private Long submissionId;

    /**
     * 测试ID
     */
    private Long quizId;

    /**
     * 学生ID
     */
    private String studentId;

    /**
     * 答案（JSON格式存储）
     * 例如：{"1":"A","2":"B","3":"C"}
     * 其中，键为问题ID，值为所选答案
     */
    private String answers;

    /**
     * 分数
     */
    private Integer score;

    /**
     * 提交时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date submitTime;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    
    /**
     * 非数据库字段：学生姓名
     */
    private String studentName;
    
    /**
     * 非数据库字段：测试信息
     */
    private Quiz quiz;
    
    /**
     * 非数据库字段：学生信息
     */
    private Student student;
    
    /**
     * 非数据库字段：答案映射
     */
    private Map<String, String> answerMap;

    /**
     * 无参构造函数
     */
    public QuizSubmission() {
    }

    /**
     * 全参构造函数
     */
    public QuizSubmission(Long submissionId, Long quizId, String studentId, String answers,
                         Integer score, Date submitTime, Date createTime, Date updateTime) {
        this.submissionId = submissionId;
        this.quizId = quizId;
        this.studentId = studentId;
        this.answers = answers;
        this.score = score;
        this.submitTime = submitTime;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }

    /**
     * 用于创建提交记录的构造函数
     */
    public QuizSubmission(Long quizId, String studentId, String answers) {
        this.quizId = quizId;
        this.studentId = studentId;
        this.answers = answers;
        this.score = 0; // 默认为0分
    }

    // Getters and Setters
    public Long getSubmissionId() {
        return submissionId;
    }

    public void setSubmissionId(Long submissionId) {
        this.submissionId = submissionId;
    }

    public Long getQuizId() {
        return quizId;
    }

    public void setQuizId(Long quizId) {
        this.quizId = quizId;
    }

    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getAnswers() {
        return answers;
    }

    public void setAnswers(String answers) {
        this.answers = answers;
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    public Date getSubmitTime() {
        return submitTime;
    }

    public void setSubmitTime(Date submitTime) {
        this.submitTime = submitTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public Quiz getQuiz() {
        return quiz;
    }

    public void setQuiz(Quiz quiz) {
        this.quiz = quiz;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public Map<String, String> getAnswerMap() {
        return answerMap;
    }

    public void setAnswerMap(Map<String, String> answerMap) {
        this.answerMap = answerMap;
    }

    @Override
    public String toString() {
        return "QuizSubmission{" +
                "submissionId=" + submissionId +
                ", quizId=" + quizId +
                ", studentId='" + studentId + '\'' +
                ", answers='" + answers + '\'' +
                ", score=" + score +
                ", submitTime=" + submitTime +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
} 